<html>
<head><meta charset="utf-8"><title>Impl to ModuleDef or similar? · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Impl.20to.20ModuleDef.20or.20similar.3F.html">Impl to ModuleDef or similar?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="227497762"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Impl%20to%20ModuleDef%20or%20similar%3F/near/227497762" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kirill Bulatov <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Impl.20to.20ModuleDef.20or.20similar.3F.html#227497762">(Feb 23 2021 at 20:25)</a>:</h4>
<p>I'm working on <a href="https://github.com/rust-analyzer/rust-analyzer/issues/7679">https://github.com/rust-analyzer/rust-analyzer/issues/7679</a> and considering the following case:</p>
<div class="codehilite"><pre><span></span><code>mod foo {
    pub struct Item;
    impl Item {
        pub const TEST_ASSOC: usize = 3;
    }
}

fn main() {
    Item::TEST_A$0;
}
</code></pre></div>
<p>I look up items for <code>TEST_A</code> and get the assoc item as a <code>ModuleDef</code>.<br>
If I try to get the <code>ModPath</code> for this def, I get <code>None</code>, which is expected.</p>
<p>There's a method on that assoc item, returning <code>AssocItemContainer</code> that's either a <code>Trait</code> or an <code>Impl</code>.<br>
<code>Trait</code> is trivial, but how can I get from that <code>Impl</code> to a struct that it belongs to?</p>



<a name="227498000"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Impl%20to%20ModuleDef%20or%20similar%3F/near/227498000" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Impl.20to.20ModuleDef.20or.20similar.3F.html#227498000">(Feb 23 2021 at 20:27)</a>:</h4>
<p>Does <code>.target_ty().as_adt()</code> help here?</p>



<a name="227498242"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Impl%20to%20ModuleDef%20or%20similar%3F/near/227498242" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kirill Bulatov <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Impl.20to.20ModuleDef.20or.20similar.3F.html#227498242">(Feb 23 2021 at 20:28)</a>:</h4>
<p>Oh, I was really close, had missed that method somehow <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span> <br>
Thank you, that helped.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>